package concurrent.c_000_Thread;

/**
 * https://www.cnblogs.com/jhxxb/p/10879983.html
 */
public class T05_Exception {
    public static void main(String[] args) {
        Thread thread = new Thread(() -> {
            int b = 5 / 0;
        });

        // 设置所有线程
        // Thread.setDefaultUncaughtExceptionHandler(new MyUncaughtExceptionHandler());

        // 捕获指定线程中的异常
        thread.setUncaughtExceptionHandler(new MyUncaughtExceptionHandler());
        thread.start();
    }

    static class MyUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
        @Override
        public void uncaughtException(Thread t, Throwable e) {
            System.out.println(Thread.currentThread().getName() + " 异常");
            e.printStackTrace();
        }
    }
}
